package com.yanxu.threadandobjectmethods.join;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025/3/1-2025
 * @Description: join 方法的本质是  wait、 notify
 *   自己使用  wait、notify 方法实现 一个 join 相似的效果。
 *
 */
public class JoinPrinciple {
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(new Runnable() {
            public void run() {
                try {
                    System.out.println("子线程运行!!!");
                    Thread.sleep(5000);
                    System.out.println("子线程运行完毕!!!");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        thread1.start();
        //thread1.join();
        synchronized (thread1){
            thread1.wait();
        }
        System.out.println("主线程运行完毕");
    }
}